-
Notifications
You must be signed in to change notification settings - Fork 2
[mercury]
Add the viteMercury
plugin for Vite environments
#646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This will help us to avoid issues when the Mercury dependency is duplicated. Also, this help us to set this mapping inline in the HTML.
This plugin replaces the need for using the CLI in Vite environments.
Also, inline the base/base bundle by default and preload the base/icons bundle by default.
Also, fix default values for mercuryOptions
…li and vite-mercury-plugin packages Now, @genexus/mercury only contains the core of Mercury, and we have packages for bulding Mercury, using it through out a CLI, and a plugin to work with Vite. Breaking changes: - The default path for the fonts is now "/assets/fonts/" instead of "./assets/fonts/" - The default path for the icons is now "/assets/icons/" instead of "./assets/icons/"
fileDir: fileMetadata.dir | ||
.replace(MERCURY_DIST_RELATIVE_FOLDERS.DIST_BUNDLES_SCSS, "") | ||
.replace("\\", "/") |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 9 hours ago
The best fix is to change .replace("\\", "/")
to use a global replacement, changing all backslashes in the path, not just the first one. This can be done by switching the argument to replace
to a regular expression: .replace(/\\/g, "/")
. This approach is concise, robust, and doesn't require any additional method definitions or third-party imports since the RegExp is supported natively. Only a single line change is necessary, at line 52 in packages/mercury-build/src/build/internal/transpile-bundle-and-create-mappings.ts.
-
Copy modified line R52
@@ -49,7 +49,7 @@ | ||
BUNDLES.push({ | ||
fileDir: fileMetadata.dir | ||
.replace(MERCURY_DIST_RELATIVE_FOLDERS.DIST_BUNDLES_SCSS, "") | ||
.replace("\\", "/") | ||
.replace(/\\/g, "/") | ||
}); | ||
|
||
const transpiledBundle = transpileBundle(filePath, true); |
fileDir: fileMetadata.dir | ||
.replace(MERCURY_SRC_RELATIVE_FOLDERS.SRC_BUNDLES_SCSS, "") | ||
.replace("\\", "/") |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 9 hours ago
To safely replace all backslashes in the directory string with forward slashes, change .replace("\\", "/")
to .replace(/\\/g, "/")
. This uses a regular expression with the global (g
) flag to ensure all backslashes are replaced, regardless of how many are present. The modification should be made directly on line 121 in packages/mercury-build/src/build/internal/transpile-bundle-and-create-mappings.ts
. No new imports or external libraries are required—the built-in String.replace
with regex is sufficient and correct.
-
Copy modified line R121
@@ -118,7 +118,7 @@ | ||
BUNDLES.push({ | ||
fileDir: fileMetadata.dir | ||
.replace(MERCURY_SRC_RELATIVE_FOLDERS.SRC_BUNDLES_SCSS, "") | ||
.replace("\\", "/") | ||
.replace(/\\/g, "/") | ||
}); | ||
|
||
const transpiledBundle = transpileBundle(actualFilePath, hasGlobantVariant); |
This plugin replaces the need for using the CLI in Vite environments.